﻿@model UserCreateDto
@Html.Extra()
@{
    Layout = "~/Views/Shared/OA/_Edit.cshtml";
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "保存", Click = "save" })
    @Html.MyNet().Button(new ButtonOptions { Text = "返回", Click = "back" })
}
@section Main
{
    @Html.HiddenFor(model => model.Id)
    <table>
        @if (string.IsNullOrEmpty(Request["Application"]))
        {
            <tr>
                <th>
                    @Html.LabelFor(model => model.Application, "应用")
                </th>
                <td>
                    @Html.MyNet().DropDownListFor(model => model.Application, Url.Action("Read", "Application"), "Key", "Name", "请选择应用", new ValidateOptions
                    {
                        RequiredError = "请选择应用"
                    })
                    @Html.MyNet().ValidationMessageFor(model => model.Application)
                </td>
            </tr>
        }
        else
        {
            Model.Application = Request["Application"];
            @Html.HiddenFor(model => model.Application)
        }
        <tr>
            <th>
                @Html.LabelFor(model => model.UserName, "用户名")
            </th>
            <td>
                @Html.MyNet().TextBoxFor(model => model.UserName, new ValidateOptions
                {
                    RequiredError = "请输入用户名",
                    LengthError = "请输入2-20个字符",
                    LengthMin = 2,
                    LengthMax = 20,
                    RemoteError = "用户名已被使用",
                    RemoteUrl = Url.Action("ValidateUserName")
                })
                @Html.MyNet().ValidationMessageFor(model => model.UserName)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.Password, "密码")
            </th>
            <td>
                @Html.MyNet().PasswordFor(model => model.Password, new ValidateOptions
                {
                    RequiredError = "请输入密码",
                    LengthError = "请输入6-20个字符",
                    LengthMin = 6,
                    LengthMax = 20,
                })
                @Html.MyNet().ValidationMessageFor(model => model.Password)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.Name, "姓名")
            </th>
            <td>
                @Html.MyNet().TextBoxFor(model => model.Name, new ValidateOptions
                {
                    LengthMax = 64
                })
                @Html.MyNet().ValidationMessageFor(model => model.Name)
            </td>
        </tr>
        @if (string.IsNullOrEmpty(Request["Application"]))
        {
            <tr>
                <th></th>
                <td>
                    @Html.CheckBoxFor(model => model.IsAdmin)
                    @Html.LabelFor(model => model.IsAdmin, "超级管理员")
                </td>
            </tr>
        }
        <tr>
            <th></th>
            <td>
                @Html.CheckBoxFor(model => model.IsEnable)
                @Html.LabelFor(model => model.IsEnable, "是否启用")
            </td>
        </tr>
    </table>
}
<script>

    function save()
    {
        var form = $("form");
        if (!form.valid()) return;

        $.ajax
        ({
            url: form.attr("action"),
            data: form.serialize(),
            type: "post",
            error: disposeError,
            success: function (result)
            {
                if (disposeException(result)) return;
                back(true, null);
            }
        });
    }

</script>
